﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RuneLog.Extensions;
namespace RuneLog.GrandExchange.GraphView
{
    public partial class GraphViewer : Form
    {
        public GraphData Data
        {
            get;
            private set;
        }
        public int MinDaily
        {
            get;
            private set;
        }
        public int MaxDaily
        {
            get;
            private set;
        }
        public int Average
        {
            get;
            private set;
        }
        public GraphViewer(GraphData data, Image i, string name)
        {
            Data = data;
            InitializeComponent();
            this.Text = "Graph Viewer - " + name;
            iconBox.Image = i;
            int minDaily = int.MaxValue, maxDaily = 0;
            long avg = 0;
            foreach (KeyValuePair<long, int> kvp in Data.Average)
            {
                double date = DateTimeExtensions.FromUnixTime(kvp.Key).ToOADate();
                itemGraph.Series["dataSeriesAverage"].Points.Add(new System.Windows.Forms.DataVisualization.Charting.DataPoint(date, kvp.Value));
            }
            foreach (KeyValuePair<long, int> kvp in Data.Daily)
            {
                if (kvp.Value > maxDaily)
                    maxDaily = kvp.Value;
                else if (kvp.Value < minDaily)
                    minDaily = kvp.Value;
                avg += kvp.Value;
                double date = DateTimeExtensions.FromUnixTime(kvp.Key).ToOADate();
                itemGraph.Series["dataSeriesDaily"].Points.Add(new System.Windows.Forms.DataVisualization.Charting.DataPoint(date, kvp.Value));
            }
            avg /= Data.Daily.Count;
            MinDaily = minDaily;
            MaxDaily = maxDaily;
            Average = avg > int.MaxValue ? int.MaxValue : (int)avg;
            minimumLabel.Text = MinDaily.ToString("#,###");
            maximumLabel.Text = MaxDaily.ToString("#,###");
            averageLabel.Text = Average.ToString("#,###");
        }
    }
}
